#include "../../server/MsgQueueManager.hpp"
#include <google/protobuf/map.h>
#include <gtest/gtest.h>
#include <unordered_map>
#include <string>

micromq::MsgQueueManager::ptr manager;

class MsgQueueTest : public testing::Environment
{
public:
    virtual void SetUp() override
    {
        manager = std::make_shared<micromq::MsgQueueManager>("./meta.db");
    }

    virtual void TearDown() override
    {
        // manager->clear();
    }
};

TEST(msg_queue_test, insert_test)
{
    // google::protobuf::Map<std::string, std::string> testMap = {{"k1", "v1"}, {"k2", "v2"}};
    google::protobuf::Map<std::string, std::string> testMap;
    manager->declareMsgQueue("e1", true, false, false, testMap);
    manager->declareMsgQueue("e2", true, false, false, testMap);
    manager->declareMsgQueue("e3", true, false, false, testMap);
    ASSERT_EQ(manager->size(), 3);
}

TEST(msg_queue_test, select_test)
{
    micromq::MsgQueue::ptr mq = manager->getMsgQueue("e1");
    ASSERT_NE(mq.get(), nullptr);
    ASSERT_EQ(mq->_name, "e1");
    ASSERT_EQ(mq->_durable, true);
    ASSERT_EQ(mq->_exclusive, false);
    ASSERT_EQ(mq->_autoDelete, false);
}

TEST(msg_queue_test, delete_test)
{
    manager->removeMsgQueue("e3");
    micromq::MsgQueue::ptr mq = manager->getMsgQueue("e3");
    ASSERT_EQ(mq.get(), nullptr);
    ASSERT_EQ(manager->isExists("e3"), false);
}

int main(int argc, char* argv[])
{
    testing::InitGoogleTest(&argc, argv);
    testing::AddGlobalTestEnvironment(new MsgQueueTest);
    RUN_ALL_TESTS();

    return 0;
}